package com.maxd.service.lucky;

import com.maxd.model.LuckyQueue;
import com.maxd.respository.lucky.LuckyQueueJpaRepository;
import com.maxd.respository.lucky.LuckyQueueRepository;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 幸运值队列类型
 */
@Service
public class LuckyQueueServiceImpl implements ILuckyQueueService {

    private final LuckyQueueJpaRepository luckyQueueJpaRepository;
    private final LuckyQueueRepository luckyQueueRepository;

    public LuckyQueueServiceImpl(LuckyQueueJpaRepository luckyQueueJpaRepository, LuckyQueueRepository luckyQueueRepository) {
        this.luckyQueueJpaRepository = luckyQueueJpaRepository;
        this.luckyQueueRepository = luckyQueueRepository;
    }


    @Override
    public LuckyQueue saveBody(LuckyQueue luckyQueue) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        luckyQueue.setCreateTime(sdf.format(new Date()));
        luckyQueue.setState(1);
        return luckyQueueJpaRepository.save(luckyQueue);
    }

    @Override
    public int deleteById(Long id){
        return luckyQueueRepository.updateLuckyQueueStateById(id);
    }

    @Override
    public LuckyQueue updateById(LuckyQueue luckyQueue) {
        return luckyQueueJpaRepository.save(luckyQueue);
    }

    @Override
    public List<LuckyQueue> selectLuckyQueueList() {
        return luckyQueueRepository.selectLuckyQueueList();
    }

    @Override
    public List<LuckyQueue> selectLuckyQueueListDesc() {
        return luckyQueueRepository.selectLuckyQueueListDesc();
    }

    @Override
    public List<LuckyQueue> selectLuckyQueueListAsc() {
        return luckyQueueRepository.selectLuckyQueueListASC();
    }


    @Override
    public LuckyQueue selectLuckyQueueBySort(Integer sort) {
        return luckyQueueRepository.selectLuckyQueueBySort(sort);
    }

    @Override
    public LuckyQueue selectLuckyQueueById(Long id) {
        return luckyQueueRepository.selectLuckyQueueById(id);
    }
}
